import tkinter as tk
from tkinter import messagebox
from datetime import datetime
import time
tasks = []

def add_task():
    task = entry_task.get()
    if task:
        tasks.append(task)
        update_listbox()
        entry_task.delete(0, tk.END)
    else:
        messagebox.showwarning("警告", "请先输入任务内容！")
def delete_task():
    try:
        index = listbox_tasks.curselection()[0]
        del tasks[index]
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def mark_as_done():
    try:
        index = listbox_tasks.curselection()[0]
        tasks[index] = tasks[index] + " (完成)"
        update_listbox()
    except IndexError:
        messagebox.showwarning("警告", "请先选择一个任务！")
def sort_by_priority():
    tasks.sort(key=lambda x: "紧急" in x, reverse=True)
    update_listbox()
def update_listbox():
    listbox_tasks.delete(0, tk.END)
    for task in tasks:
        listbox_tasks.insert(tk.END, task)

root = tk.Tk()
root.title("待办事项列表")


entry_task = tk.Entry(root, width=50)
entry_task.pack(pady=10)

button_add = tk.Button(root, text="添加任务", command=add_task)
button_add.pack(pady=5)



listbox_tasks = tk.Listbox(root, height=10, width=50)
listbox_tasks.pack(pady=10)

button_delete = tk.Button(root, text="删除任务", command=delete_task)
button_delete.pack(pady=5)

button_done = tk.Button(root, text="标记为完成", command=mark_as_done)
button_done.pack(pady=5)

button_sort = tk.Button(root, text="按紧急程度排序", command=sort_by_priority)
button_sort.pack(pady=5)

def show_about_info():
    messagebox.showinfo("关于", "这是一个简单的待办事项小程序。\n作者：Your Name")


# 函数：显示提醒窗口
def show_reminder():
    messagebox.showinfo("提醒", "这是一个提醒窗口。")

menu_bar = tk.Menu(root)
root.config(menu=menu_bar)
# 添加菜单栏中的选项
file_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="文件", menu=file_menu)
file_menu.add_command(label="退出", command=root.quit)

help_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="帮助", menu=help_menu)
help_menu.add_command(label="关于", command=show_about_info)

remind_menu = tk.Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="提醒", menu=file_menu)
remind_menu.add_command(label="提醒", command=show_reminder)
root.mainloop()
